package com.junzhiit.nengji.api.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.SystemTypeService;
import com.junzhiit.nengji.api.web.vo.ResultVO;
import com.junzhiit.nengji.api.web.vo.SystemTypeConditionVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/system/type")
public class SystemTypeController extends BaseController {
	
	@Autowired
	private SystemTypeService systemTypeService;
	
	@ApiOperation(value = "查询所有分类信息,未分类")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO findAll() {
		return systemTypeService.findAll();
	}
	
	@ApiOperation(value = "查询所有分类信息,按照等级分好类")
	@RequestMapping(value = "/grading",method = RequestMethod.GET)
	public ResultVO findAllGrading() {
		return systemTypeService.findAllGrading();
	}
	
	@ApiOperation(value = "查询所有分类信息的名称,未分类")
	@RequestMapping(value = "/name",method = RequestMethod.GET)
	public ResultVO findAllName() {
		return systemTypeService.findAllName();
	}
	
	@ApiOperation(value = "查询所有分类信息的名称,按照等级分好类")
	@RequestMapping(value = "/name/grading",method = RequestMethod.GET)
	public ResultVO findAllGradingName() {
		return systemTypeService.findAllNameGrading();
	}

	@ApiOperation(value = "查询具体某个分类信息")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findbyid(@PathVariable String id) {
		return systemTypeService.findbyid(id);
	}

	@ApiOperation(value = "按照条件查询某个/某些分类信息")
	@RequestMapping(value="/condition",method = RequestMethod.GET)
	public ResultVO getAllByCondition(SystemTypeConditionVO type) {
		return systemTypeService.getAllByCondition(type);
	}
	
	@ApiOperation(value="根据系统分类ID查询所有该分类的商品")
	@RequestMapping(value="/goods/{id}",method=RequestMethod.GET)
	public ResultVO getGoodsByType(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required");
		return systemTypeService.getGoodsByType(id);
	}
}
